# -*- coding: utf-8 -*-

# Define your item pipelines here
#
# Don't forget to add your pipeline to the ITEM_PIPELINES setting
# See: https://doc.scrapy.org/en/latest/topics/item-pipeline.html


import json

class TencentspiderPipeline(object):

    def __init__(self):
        # isinstance
        self.file = open('tencent.json', 'a', encoding='utf-8')
        self.file2 = open('positiondescribe.json', 'a', encoding='utf-8')

    def process_item(self, item, spider):
        if item.__class__.__name__ == 'TencentspiderItem':
            jsontext = json.dumps(dict(item), ensure_ascii=False) + ',\n'
            self.file.write(jsontext)
        else:
            jsontext = json.dumps(dict(item), ensure_ascii=False) + ',\n'
            self.file2.write(jsontext)

        return item

    def close_spider(self, spider):
        self.file.close()
        self.file2.close()